package com.team.util;

import org.springframework.web.multipart.commons.CommonsMultipartFile;

import java.io.File;
import java.io.IOException;

public class FileUploadUtil {
 public static String uploadFile(String savePath, CommonsMultipartFile file){
  try {
   //生成唯一文件名
   String uploadFileName=file.getOriginalFilename();
   String expname=uploadFileName.substring(uploadFileName.lastIndexOf("."));
   String fileName=System.currentTimeMillis()+expname;
   //上传文件
   File saveFile=new File(savePath+"/"+fileName);
   file.transferTo(saveFile);//上传
   return fileName;  //返回文件名称
  } catch (Exception e) {
   e.printStackTrace();
  }
  return null;
 }
}
